#include "StdAfx.h"
#include "ring_2.h"
#include <algorithm>

bool ring_2::within(const point_2& point) const
{
  point_2 center(center_x, center_y);

  return point.distance2(center) < radius*radius;
}

bool ring_2::adjacent(const point_2& point, int tolerance) const
{
  double lower_radius = std::max(radius-tolerance, 0.0);
  double upper_radius = radius + tolerance;

  point_2 center(center_x, center_y);

  return (point.distance2(center)<upper_radius*upper_radius) &&
    (point.distance2(center)>lower_radius*lower_radius);
}

bool ring_2::intersects(const box_2& box) const
{
  point_2 left(center_x-radius, center_y);
  point_2 right(center_x+radius, center_y);
  point_2 top(center_x, center_y-radius);
  point_2 bottom(center_x, center_y+radius);

  return box.within(top) || box.within(bottom) ||\
    box.within(left) || box.within(right);
}
